package com.android.commcount.ui.activity;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.baselibrary.interface_.CommCallBack;
import com.android.baselibrary.interface_.OkHttpCallBack;
import com.android.baselibrary.responce.BaseResponce;
import com.android.baselibrary.tool.CommLoading;
import com.android.baselibrary.tool.CommToast;
import com.android.baselibrary.util.GlideUtil;
import com.android.baselibrary.view.Comm_HeadView;
import com.android.baselibrary.view.MultiStateView;
import com.android.commcount.Lib_CommCount;
import com.android.commcount.R;
import com.android.commcount.R2;
import com.android.commcount.adapter.CommCount_Record_HistoryAdapter;
import com.android.commcount.adapter.MyCountTypeListAdapter;
import com.android.commcount.bean.CommCount_Type;
import com.android.commcount.manager.API_Manager;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

import java.util.List;

import butterknife.BindView;

public class MyCountTypeListActivity extends BaseActivity {

    @BindView(R2.id.multiplestatusView)
    MultiStateView multiplestatusView;
    @BindView(R2.id.comm_title)
    Comm_HeadView comm_title;
    @BindView(R2.id.recyclerview)
    RecyclerView recyclerview;
    @BindView(R2.id.smartrefreshlayout)
    SmartRefreshLayout smartrefreshlayout;

    MyCountTypeListAdapter adapter;

    boolean isShowSelect = false;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_onlylist;
    }

    @Override
    protected void initView() {
        comm_title.setTitle("我的模板");
        isShowSelect = getIntent().getBooleanExtra("isShowSelect", false);

        recyclerview.setLayoutManager(new LinearLayoutManager(mContext));
        adapter = new MyCountTypeListAdapter(mContext, itemClick);
        recyclerview.setAdapter(adapter);


        smartrefreshlayout.setEnableRefresh(false);
        smartrefreshlayout.setEnableLoadMore(false);
    }

    CommCallBack itemClick = new CommCallBack() {
        @Override
        public void onResult(Object obj) {
            if (isShowSelect) {
                int index = (int) obj;
                for (int i = 0; i < adapter.list.size(); i++) {
                    if (index == i) {
                        adapter.list.get(i).isShowOnHome = 1;
                    } else {
                        adapter.list.get(i).isShowOnHome = 0;
                    }
                    adapter.list.get(i).save();
                }
                setResult(200);
                finish();
            }
        }
    };

    @Override
    protected void initData() {
        getData();
    }

    private void getData() {
        Lib_CommCount.getInstance().getTypeList(mContext, new CommCallBack() {
            @Override
            public void onResult(Object obj) {
                List<CommCount_Type> commCountTypes = (List<CommCount_Type>) obj;
                adapter.setData(commCountTypes);
            }
        });
    }

//    @OnClick({R.id.tv_sendcode})
//    public void onViewClicked(View view) {
//        switch (view.getId()) {
//            case R.id.tv_sendcode:
//                break;
//        }
//    }

}
